//
//  SharedMapView.m
//  SmartLife
//
//  Created by Lawrence on 15/10/26.
//  Copyright © 2015年 Lawrence. All rights reserved.
//

#import "SharedMapView.h"

@interface SharedMapView(){
    NSMutableArray *_internalStatusArray;
}
@property(nonatomic,readwrite) MAMapView *mapView;
@end

@implementation SharedMapView


+(instancetype)sharedInstance{
    
    static SharedMapView *sharedInstance=nil;
    
    static dispatch_once_t onceToken;
    
    //oc 单例
    dispatch_once(&onceToken, ^{
        sharedInstance=[[SharedMapView alloc] init];
    });
    return sharedInstance;
}

-(instancetype)init{
    if (self=[super init]) {
        [self initProperties];
        [self createMapView];
    }
    return self;
}

-(void)initProperties{
    _internalStatusArray=[[NSMutableArray alloc] init];
}

-(void)createMapView{
    if (self.mapView==nil) {
        self.mapView=[[MAMapView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    }
}


#pragma mark Interface ---接口
-(void)stashMapViewStatus{
    
    // oc 线程锁 －－－如果当前的对象不为空，则退
    @synchronized(_internalStatusArray) {
        if (_internalStatusArray==nil) {
            return;
        }
        [_internalStatusArray addObject:[self.mapView getMapStatus]];
    }
}


-(void)popMapViewStatus{
    
    @synchronized(_internalStatusArray) {
        if (_internalStatusArray==nil||![_internalStatusArray count]) {
            return;
        }
        [self.mapView setMapStatus:[_internalStatusArray lastObject] animated:NO];
        [_internalStatusArray removeLastObject];
    }
}
@end
